package com.lpj;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class CallBean implements Writable {
    private String phoneNumber;//手机号
    private long callOut;//打出电话
    private long callIn; //接入电话
    private long sumCalls;//总通讯电话

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public long getCallOut() {
        return callOut;
    }

    public void setCallOut(long callOut) {
        this.callOut = callOut;
    }

    public long getCallIn() {
        return callIn;
    }

    public void setCallIn(long callIn) {
        this.callIn = callIn;
    }

    public long getSumCalls() {
        return sumCalls;
    }

    public void setSumCalls(long sumCalls) {
        this.sumCalls = sumCalls;
    }

    //在反序列化时候，反射机制需要调用空参的构造函数，所以定义了一个空参的构造函数
    public CallBean() {

    }

    //为了对象数据的初始化方便，加入一个带参的构造函数
    public CallBean(String phoneNumber,long callIn,long callOut) {
        this.phoneNumber=phoneNumber;
        this.callIn=callIn;
        this.callOut=callOut;
        this.sumCalls=callIn+callOut;
    }

    //重写toString()方法
    @Override
    public String toString() {
        return ""+callIn+"\t"+callOut+"\t"+sumCalls+"";
    }

    //从数据流中反序列出对象的数据
    //从数据流中读取字段时必须和序列化的顺序保持一致
    public void readFields(DataInput in) throws IOException {
        phoneNumber=in.readUTF();
        callIn=in.readLong();
        callOut=in.readLong();
        sumCalls=in.readLong();
    }

    //将对象数据序列化到流中
    public void write(DataOutput out) throws IOException{
        out.writeUTF(phoneNumber);
        out.writeLong(callIn);
        out.writeLong(callOut);
        out.writeLong(sumCalls);
    }
}
